mcnemar_table: Contingency table for McNemar's test
confusion matrix(混同行列)とは異なる
code:example.py
>> import numpy as np
>> from mlxtend.evaluate import mcnemar_table
>> y_model1 = np.array(0, 1, 0, 0, 0, 1, 1, 0, 0, 0) # 正, 誤, 正, 正, 正, 正, 正, 誤, 誤, 誤 >> y_model2 = np.array(0, 0, 1, 1, 0, 1, 1, 0, 0, 0) # 正, 正, 誤, 誤, 正, 正, 正, 誤, 誤, 誤 >> tb = mcnemar_table(y_true, y_model1, y_model2)
>> tb
出力される2x2のNumPy arrayについて
a: tb[0, 0]: # of samples that both models predicted correctly
b: tb[0, 1]: # of samples that model 1 got right and model 2 got wrong
c: tb[1, 0]: # of samples that model 2 got right and model 1 got wrong
d: tb[1, 1]: # of samples that both models predicted incorrectly
code:python
m1_vs_true, m2_vs_trueをmodel1,2それぞれとtrueとの同値性(==)を見て、1/0のarrayとする
plus_true = m1_vs_true + m2_vs_true
minus_true = m1_vs_true - m2_vs_true
plus_trueだけだと1の区別がつかない(1+0 or 0+1)ので導入したという理解
tb[0, 0] = np.sum(plus_true == 2):m1もm2も正解 (1+1)
tb[0, 1] = np.sum(minus_true == 1):m1正解、m2不正解 (1-0)
tb[1, 0] = np.sum(minus_true == -1):m1不正解、m2正解 (0-1)
tb[1, 1] = np.sum(plus_true == 0):m1もm2も不正解 (0+0)